import storage from "@/utils/storage.js"
import {CURRENT_TRAVEL} from "@/store/mutations_type.js"
import * as Travel from "@/core/constant/travel.js"
export default{
	namespaced:true,
	state:{
		currentTravel:null, // 指已经成功碰面（TRAVEL_GOING）的出行
		travelTimer:null
	},
	mutations:{
		SET_TRAVEL_TIMER(state,value){
			state.travelTimer = value
		},
	},
	actions:{
		clearTravels({state}){
			if(state.travelTimer){
				state.travelTimer.travels = []
			}
		},
		setCurrentTravel({state},travel){
			state.currentTravel = travel
			storage.set(CURRENT_TRAVEL,travel)
		},
		removeTravel({state},travelId){
			for(const [index,t] of state.travelTimer.travels.entries()){
				if(t.travelId === +travelId){
					state.travelTimer.travels.splice(index,1)
					break
				}
			}
		},
		setCurrentTravelStatus({state},status){
			state.currentTravel.status = status
			if(state.currentTravel.status === Travel.TRAVEL_EVALUATED){
				storage.remove(CURRENT_TRAVEL)
				return
			}
			storage.set(CURRENT_TRAVEL,state.currentTravel)
		},
	}
}